﻿#ifndef MVBPROTOCALCACHE_H
#define MVBPROTOCALCACHE_H

#include<QMap>
#include"mvbportdata.h"
#include"mvbdevicedata.h"
/*******************************
fileName；mvbprotocalcache.h
date:2024-12-02
author:bang
describe:用于缓存加载的mvb端口协议文件内容
*******************************/

class MVBProtocalCache
{
public:
    MVBProtocalCache();
    QMap<QString,mvbDeviceData> m_portCache;
    QMap<QString,MVBPortData>   m_portDataPars;     //解析后的端口数据

    void TransCacheToDataPars();
    void TransCacheToDataPars(const QString& portAddress);
    void setPortCache();
    //写入端口数据
    void WritePortData(const QString& portAddress,const QString& varName,const QVariant& value,int varID);

    void resetAllDeviceData();
    void printHexData(unsigned short *data, unsigned int size);
protected:

    //数组转变量
    void deviceDataToPortVars(const mvbDeviceData& deviceData, MVBPortData& portVars,int Varid);
    //变量转 设备的char数组
    void portVarsToDeviceData(const MVBPortData& portVars,mvbDeviceData& deviceData,int Varid);

    short invertBit(short value, int bitIndex);
};

#endif // MVBPROTOCALCACHE_H
